package com.hotpot.sys.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.hotpot.comm.base.BaseController;
import com.hotpot.comm.base.PageUtils;
import com.hotpot.comm.base.Query;
import com.hotpot.comm.base.R;
import com.hotpot.sys.pojo.SysUser;
import com.hotpot.sys.service.SysUserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * 描述:
 * @author myx
 * @date 2017年7月11日 下午10:10:40
 */
@RestController
@RequestMapping(value = "/sysusers")
@Api(value = "测试",tags = "测试用例")
public class SysUserController extends BaseController{
	@Autowired
	private SysUserService sysUserService;
	
	/**
	 * 方法描述：分页获取用户列表
	 * @param params
	 * @return
	 * @return: R
	 */
	@ApiOperation(value = "获取系统用户列表", notes = "")
	@RequestMapping(value = { "" }, method = RequestMethod.POST)
	public R getUserList(@RequestBody Map<String, Object> param) {
		//查询列表数据
		Query query = new Query(param);
		int total = sysUserService.queryTotal(query);//查询总数
		List<SysUser> sysUserList = sysUserService.queryList(query);//查询数据列表
		PageUtils pageUtil = new PageUtils(sysUserList, total, query.getLimit(), query.getPage());
		return renderSuccess(pageUtil);
	}
	
	
	/**
	 * 方法描述：保存用户信息
	 * @param sysUser
	 * @return
	 * @return: R
	 */
	@ApiOperation(value = "创建用户", notes = "根据SysUser对象创建用户")
	@ApiImplicitParam(name = "sysUser", value = "用户详细实体user", required = true, dataType = "SysUser")
	@RequestMapping(value = "", method = RequestMethod.DELETE)
	public R saveUserList(@RequestBody SysUser sysUser){
		boolean flag=sysUserService.save(sysUser);
		if(flag){
			return renderSuccess(null);
		}
		return renderError();
	}
	
	/**
	 * 方法描述：更新用户信息
	 * @param sysUser
	 * @return
	 * @return: R
	 */
	@ApiOperation(value = "更新用户详细信息", notes = "根据url的id来指定更新对象，并根据传过来的user信息来更新用户详细信息")
	@ApiImplicitParam(name = "sysUser", value = "用户详细实体user", required = true, dataType = "SysUser")
	@RequestMapping(value = "", method = RequestMethod.PUT)
	public R updateUserList(@RequestBody SysUser sysUser){
		boolean flag=sysUserService.upate(sysUser);
		if(flag){
			return renderSuccess(null);
		}
		return renderError();
	}
	
	
}
